package br.unifor.g2cl.hl;


import java.io.IOException;
import java.net.SocketAddress;
import java.util.Vector;

import br.unifor.g2cl.SuspectedException;
import br.unifor.g2cl.TimeoutException;
import br.unifor.g2cl.hl.listener.MessageDispatcherListener;

import net.sf.jgcs.ControlSession;
import net.sf.jgcs.DataSession;
import net.sf.jgcs.Message;
import net.sf.jgcs.Service;
import net.sf.jgcs.UnsupportedServiceException;
import net.sf.jgcs.membership.MembershipListener;

public interface IMessageDispatcher {
	

	public void setMessageDispatcherListener(MessageDispatcherListener messageDispatcherListener);
	
	/**
	 * To set your MembershipListener since this object will set itself
	 * as the listener.
	 * 
	 * @param membershipListener
	 */
	public void setMembershipListener(MembershipListener membershipListener);

	
	public RspList castMessage(	final Vector<SocketAddress> dests, 
								Message msg, int mode, long timeout) throws UnsupportedServiceException, IOException;

	
	/**
	 * Sends a message to a single member (destination = msg.dest) and returns the response. The message's destination
	 * must be non-zero !
	 * @throws IOException 
	 * @throws UnsupportedServiceException 
	 */
	public Object sendMessage(Message msg, SocketAddress dest, int mode,
			long timeout) throws TimeoutException, SuspectedException,
			UnsupportedServiceException, IOException;

	
	public void stop();

	public ControlSession getControlSession();

	public DataSession getDataSesson();
	
	public Service getService();

	/** Determines whether local responses should be processed. */
	public boolean isLocal();

	/** Sets whether local responses should be processed. Default is true */
	public void setLocal(boolean local);
}

